package com.zr.shortlink.admin.toolkit;

import java.util.Random;

/**
 * 随机验证码生成工具类
 * 用于生成包含数字和大小写字母的 6 位随机字符串
 */
public final class RandomGenerator {

    // 可选字符集合：0-9 + A-Z + a-z
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    private static final int CODE_LENGTH = 6;

    private static final Random RANDOM = new Random();

    /**
     * 生成 6 位随机验证码
     *
     * @return 6 位随机字符串
     */
    public static String generateCode() {
        return generateCode(6);
    }

    // 可扩展：生成指定长度
    public static String generateCode(int length) {
        StringBuilder code = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = RANDOM.nextInt(CHARACTERS.length());
            code.append(CHARACTERS.charAt(index));
        }
        return code.toString();
    }


}
